package org.summer.lawyer.controller.admin;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.summer.common.core.domain.R;
import org.summer.common.log.annotation.Log;
import org.summer.common.log.enums.BusinessType;
import org.summer.common.mybatis.core.page.PageQuery;
import org.summer.common.mybatis.core.page.TableDataInfo;
import org.summer.lawyer.domain.vo.banner.BannerCreateVo;
import org.summer.lawyer.domain.vo.banner.BannerUpdateVo;
import org.summer.lawyer.domain.vo.banner.BannerVo;
import org.summer.lawyer.service.IBannerService;

import java.util.List;

/**
 *
 */
@Tag(name = "后台相关接口")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/banner")
public class BannerController {

    private final IBannerService bannerService;

    @Operation(description = "查询Banner列表")
    @SaCheckPermission("banner:banner:list")
    @GetMapping("/list")
    public TableDataInfo<BannerVo> list(BannerVo vo, PageQuery pageQuery){
        return bannerService.selectPage(vo, pageQuery);
    }

    @Operation(description = "添加Banner")
    @Log(title = "添加Banner", businessType = BusinessType.INSERT)
    @SaCheckPermission("banner:banner:add")
    @PostMapping("/saveBanner")
    public R<Void> saveBanner(@Validated @RequestBody BannerCreateVo vo){
        bannerService.saveBanner(vo);
        return R.ok();
    }

    @Operation(description = "更新Banner")
    @Log(title = "更新Banner", businessType = BusinessType.UPDATE)
    @SaCheckPermission("banner:banner:edit")
    @PostMapping("/updateBanner")
    public R<Void> updateBanner(@Validated @RequestBody BannerUpdateVo vo){
        bannerService.updateBanner(vo);
        return R.ok();
    }

    @Operation(description = "删除Banner")
    @Log(title = "删除Banner", businessType = BusinessType.DELETE)
    @SaCheckPermission("banner:banner:remove")
    @DeleteMapping("/{ids}")
    public R<Void> removeBanner(@NotEmpty(message = "主键不能为空") @PathVariable("ids") Long[] ids){
        bannerService.deleteBanner(List.of(ids));
        return R.ok();
    }

    @Operation(description = "获取Banner信息")
    @SaCheckPermission("banner:banner:query")
    @GetMapping("/{id}")
    public R<BannerVo> getInfo(@NotNull(message = "主键不能为空")@PathVariable("id")Long id){
        return R.ok(bannerService.selectBannerVoById(id));
    }
}
